import {fetchChannlesListAPI,ChannelItem} from '@/apis/channels_api'
import { useEffect, useState } from 'react'
 
 const  useTabs =()=>{
    //频道列表状态数据
    const [channels,setChannels] =useState<ChannelItem[]>([])

    useEffect(()=>{
        const getChannelList= async ()=>{
        try{
            const  res = await fetchChannlesListAPI()
            setChannels(res.data.data.channels)
        }catch(error){
            //抛出异常信息
            throw new Error('fetchChannelList error ' + error)
        }
        }

        getChannelList()
    },[])

    //将状态数据或方法进行return出去
    return {
        channels,
    }

} 

export {useTabs}